/* 
 * File:   ipd_img.h
 * Author: dima
 *
 * Created on 5 января 2015 г., 11:13
 */

#ifndef IPD_IMG_H
#define	IPD_IMG_H
#include <cstddef>
namespace ipd {
#define sz_RGB 3

    enum color_model {
        undefined,
        tp_mono,
        tp_RGB
    };

    class ipd_img {
    public:
        ipd_img(unsigned char maximum_color = 255, unsigned char minimum_color = 0);
        void init(int w, int h, color_model color_type, unsigned char *buf); //object initialization
        void init(int w, int h, color_model color_type = tp_RGB); //object initialization
        void copy_img(const ipd_img& orig); // copy image
        virtual ~ipd_img();
        void create_image(); // create buffer for image and color depending on the type of image(RGB or monochrome)
        unsigned char* get_color(int w, int h); // get color from pixel
        void set_color(int w, int h, unsigned char* color); // set color from pixel
        unsigned int get_size() const; // Get the number of bytes in the picture
        ipd_img* operator-(const ipd_img &img); // subtraction image(masking)
        ipd_img* operator+(const ipd_img &img); // addition image(averaging image)
        ipd_img* operator-=(const ipd_img &img); // subtraction image(masking)
        ipd_img* operator+=(const ipd_img &img); // addition image(averaging image)

        inline int get_width() const; //get width image
        inline void set_width(int w); //set width image
        inline int get_height() const; //get height image    
        inline void set_height(int h); //set height image
        inline color_model get_color_type() const; // get color model image
        inline void set_color_type(color_model color_type); // set color model image
        inline unsigned char* get_data(); // get image data
        inline int get_max_color() const; // get maximum color value
        inline int get_min_color() const; // get minimum color value
    private:
        ipd_img(const ipd_img& orig);
        void copy_buf_image(unsigned char *buf); // copy image buffer
        void delete_image(); // delete image buffer
        void check_color_value(unsigned char color);
        int width;
        int height;
        unsigned char *buf_image;
        color_model type_img;
        const int max_color; //maximum color value 255
        const int min_color; //minimum color value 0

    };

    int ipd_img::get_width() const//get width image
    {
        return width;
    }

    void ipd_img::set_width(int w) //set width image
    {
        width = w;
    }

    int ipd_img::get_height() const//get height image    
    {
        return height;
    }

    void ipd_img::set_height(int h) //set height image
    {
        height = h;
    }

    color_model ipd_img::get_color_type() const // get color model images
    {
        return type_img;
    }

    void ipd_img::set_color_type(color_model color_type) // set color model images
    {
        type_img = color_type;
    }

    unsigned char* ipd_img::get_data() // get image data
    {
        return buf_image;
    }

    int ipd_img::get_max_color() const // get maximum color value
    {
        return max_color;
    }

    int ipd_img::get_min_color() const // get minimum color value
    {
        return min_color;
    }
}
#endif	/* IPD_IMG_H */

